package reflect;

import java.lang.reflect.Constructor;

/**
 * 反射机制可以破坏单例模式
 */
public class ReflectDemo07 {
    public static void main(String[] args) throws Exception{

        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
        System.out.println(s1);
        System.out.println(s2);


        Class cls = Class.forName("reflect.Singleton");

        Constructor c = cls.getDeclaredConstructor();
        c.setAccessible(true);
        Object o = c.newInstance();
        System.out.println(o);
        c.setAccessible(false);

    }
}
